package com.tan.lighting.disruptor.adapter;

import com.lmax.disruptor.dsl.Disruptor;
import com.tan.lighting.cmdservice.ExampleCmdService;
import com.tan.lighting.cmdservice.impl.ExampleCmdServiceImpl;
import com.tan.lighting.ddd.CommonCommand;
import com.tan.lighting.disruptor.event.CommandEvent;
import com.tan.lighting.domain.DefaultBsnsServResult;


/**
 * Created by tan on 2017/9/12.
 */
public class DisruptorExampleCmdService extends DisruptorCmdServiceBase implements ExampleCmdService {

    private Disruptor<CommandEvent> coreCmdDisruptor;


    private ExampleCmdServiceImpl exampleCmdServiceImpl;

    @Override
    public DefaultBsnsServResult test(String memberId, Integer count, Long currentTime) {
        CommonCommand cmd = new CommonCommand(ExampleCmdServiceImpl.class.getName(), "test", memberId, count, currentTime);
        return publishEvent(coreCmdDisruptor, cmd, () -> {
            DefaultBsnsServResult result = exampleCmdServiceImpl.test(cmd.getParameter(), cmd.getParameter(), cmd.getParameter());
            return result;
        });
    }

    @Override
    public DefaultBsnsServResult search(String memberId, Integer count, Long currentTime) {
        DefaultBsnsServResult result = exampleCmdServiceImpl.search(memberId, count, currentTime);
        return result;
    }

    public Disruptor<CommandEvent> getCoreCmdDisruptor() {
        return coreCmdDisruptor;
    }

    public void setCoreCmdDisruptor(Disruptor<CommandEvent> coreCmdDisruptor) {
        this.coreCmdDisruptor = coreCmdDisruptor;
    }

    public ExampleCmdServiceImpl getExampleCmdServiceImpl() {
        return exampleCmdServiceImpl;
    }

    public void setExampleCmdServiceImpl(ExampleCmdServiceImpl exampleCmdServiceImpl) {
        this.exampleCmdServiceImpl = exampleCmdServiceImpl;
    }
}
